]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dateMenu: Clean up timezone offset calculation a bit
authorJonas Dreßler <verdre@v0yd.nl>
Thu, 19 Mar 2020 19:48:12 +0000 (20:48 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Thu, 19 Mar 2020 21:16:47 +0000 (21:16 +0000)
Use const variables and change some names to make showing minute-offsets
in the next commit a bit more straightforward.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1107

js/ui/dateMenu.js

index cdbe0ac415207e56e679889c46ef506924d5bcb0..14a0ef48d669f3e2baa489441cad31001d9b7511 100644 (file)
@@ -180,14 +180,19 @@ class WorldClocksSection extends St.Button {
 
             let time = new St.Label({ style_class: 'world-clocks-time' });
 
-            let otherOffset = this._getTimeAtLocation(l).get_utc_offset();
-            let offset = (otherOffset - localOffset) / GLib.TIME_SPAN_HOUR;
-            let fmt = Math.trunc(offset) == offset ? '%s%.0f' : '%s%.1f';
-            let prefix = offset >= 0 ? '+' : '-';
-            let tz = new St.Label({ style_class: 'world-clocks-timezone',
-                                    text: fmt.format(prefix, Math.abs(offset)),
-                                    x_align: Clutter.ActorAlign.END,
-                                    y_align: Clutter.ActorAlign.CENTER });
+            const utcOffset = this._getTimeAtLocation(l).get_utc_offset();
+            const offsetCurrentTz = utcOffset - localOffset;
+            const offsetHours = offsetCurrentTz / GLib.TIME_SPAN_HOUR;
+
+            const fmt = Math.trunc(offsetHours) == offsetHours ? '%s%.0f' : '%s%.1f';
+            const prefix = offsetCurrentTz >= 0 ? '+' : '-';
+
+            const tz = new St.Label({
+                style_class: 'world-clocks-timezone',
+                text: fmt.format(prefix, Math.abs(offsetHours)),
+                x_align: Clutter.ActorAlign.END,
+                y_align: Clutter.ActorAlign.CENTER,
+            });
 
             time.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
             tz.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;